// Created by Windward Studios - no copyright is claimed. This code can be used in
// any manner by anyone for any reason. There is no copyright of any kind on it. You may
// use it in commercial products. You may change it without sharing those changes.
// We ask that you keep the "created by Windward Studios" in a comment at the top.

namespace net.windward.utils.ado
{

	/// <summary>
	/// Enums and delegates for iWrDatabase.
	/// </summary>
	public static class WrDatabase
	{
		/// <summary>
		/// For the LoadStatus delegate.
		/// </summary>
		public enum TYPE
		{
			/// <summary>
			/// Reading the database.
			/// </summary>
			START,
			/// <summary>
			/// Reading the tables.
			/// </summary>
			TABLES,
			/// <summary>
			/// Reading a table.
			/// </summary>
			TABLE,
			/// <summary>
			/// Reading a table.column
			/// </summary>
			TABLE_COLUMN,
			/// <summary>
			/// Reading the views.
			/// </summary>
			VIEWS,
			/// <summary>
			/// Reading a view.
			/// </summary>
			VIEW,
			/// <summary>
			/// Reading a view.column.
			/// </summary>
			VIEW_COLUMN,
			/// <summary>
			/// Reading the stored procedures.
			/// </summary>
			PROCEDURES,
			/// <summary>
			/// Reading a stored procedure.
			/// </summary>
			PROCEDURE,
			/// <summary>
			/// Reading a procedure.parameter.
			/// </summary>
			PARAMETER,
			/// <summary>
			/// XML Element.
			/// </summary>
			ELEMENT,
			/// <summary>
			/// XML Attribute
			/// </summary>
			ATTRIBUTE,
			/// <summary>
			/// Something else
			/// </summary>
			OTHER
		} ;

		/// <summary>
		/// Called by the BuildNode event to show what it is processing when reading in a datasource schema.
		/// </summary>
		/// <param name="type">What object is being read.</param>
		/// <param name="name">The name of the object reading. Can be null.</param>
		public delegate void LoadStatus(TYPE type, string name);
	};

	/// <summary>
	/// A database on a server.
	/// </summary>
	public interface IWrDatabase
	{

		/// <summary>
		/// The name of the database.
		/// </summary>
		string Name
		{ get; }

		/// <summary>
		/// The default schema for all objects in this database. Returns null if there is no default.
		/// </summary>
		string DefaultSchema
		{ get; }

		/// <summary>
		/// All tables in this database. Must call LoadMetadata first.
		/// </summary>
		WrTable[] Tables
		{ get; }

		/// <summary>
		/// All views in this database. Must call LoadMetadata first.
		/// </summary>
		WrView[] Views
		{ get; }

		/// <summary>
		/// Return all stored procedures in this database. Must call LoadMetadata first.
		/// </summary>
		WrStoredProcedure[] StoredProcedures
		{ get; }

		/// <summary>
		/// Loads the metadata for this database.
		/// </summary>
		/// <param name="credentials">The user credentials to access the database.</param>
		/// <param name="owner">Determines what metadata objects are read and if full metadata is retrieved.</param>
		/// <param name="status">Provides updates when reading in the metadata.</param>
		void LoadMetadata(WrCredentials credentials, WrVendor.ELEM_OWNER owner, WrDatabase.LoadStatus status);

		/// <summary>
		/// Loads the metadata for this database.
		/// </summary>
		/// <param name="connStr">The connection string to access the database.</param>
		/// <param name="owner">Determines what metadata objects are read and if full metadata is retrieved.</param>
		/// <param name="status">Provides updates when reading in the metadata.</param>
		void LoadMetadata(string connStr, WrVendor.ELEM_OWNER owner, WrDatabase.LoadStatus status);
	}
}
